package sort;

import java.util.Arrays;

public class ShellSort { // 希尔排序
    public static void main(String[] args) {
        int[] array = {27,15,19,28,68,6};
        shellSort(array);
        System.out.println(Arrays.toString(array));
    }
    public static void shellSort(int[] array){
        int gap = array.length;
        while (gap > 1){
            shell(array, gap);
            gap /= 2;
        }
        shell(array, 1);
    }
    public static void shell(int[] array, int gap){
        for (int i = gap; i < array.length; i++) {
            int temp = array[i];
            int j = i - gap;
            for (; j >= 0; j -= gap) {
                if(array[j] > temp){
                    array[j + gap] = array[j];
                } else {
                    break;
                }
            }
            array[j+gap] = temp;
        }
    }
}
